function [markup_owner, negativemarkup_retail] = invertcost(share,prob_i,sim_pcoeff,...
    ind_mkt_end,ind_mkt_start, carrier_ind,oem_ind,...
    mkt_set0, setup)


n_mkt = length(ind_mkt_start);
n_smln = size(prob_i, 2); 

n_mc = ind_mkt_end(n_mkt) - ind_mkt_start(1)+1;
markup_owner = nan(n_mc, 1);
negativemarkup_retail = nan(n_mc, 1);

markup_owner0 = cell(n_mkt, 1);
negativemarkup_carrier0 = cell(n_mkt, 1);

if isempty(mkt_set0)
    
    mkt_set = 1 : n_mkt;
    
else
    
    mkt_set = reshape(mkt_set0, [1 length(mkt_set0)]);
    
end

for t = mkt_set
    [markup_t, negativemarkup_retail_t] = invertcost_t(t, ind_mkt_start, ind_mkt_end, share, prob_i, ...
        sim_pcoeff, n_smln, carrier_ind, oem_ind, setup);
    markup_owner0{t} = markup_t;
    negativemarkup_carrier0{t} = negativemarkup_retail_t;
end

for t = mkt_set
    ind_t = ind_mkt_start(t):ind_mkt_end(t);
    markup_owner(ind_t) = markup_owner0{t};
    negativemarkup_retail(ind_t) = negativemarkup_carrier0{t};
end
